<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .active {
      width: 100px;
      height: 100px;
      background: saddlebrown;
    }
  </style>
</head>

<body>
  <div id="con"></div>
  <script>
    var str = `hello
            <br />
             world`
    console.log(str)

    // 模板字符串中加入变量和表达式  ${}
    let age = 17;
    var str2 = `你的年龄是${age},你${age > 18 ? '成年' : '未成年'}`;
    console.log(str2)
    var flag = false;
    var str3 = `<div class="${flag ? 'active' : ''}">你好</div>`
    document.getElementById("con").innerHTML = str3;

    var str4 = `你今天的体重是${tizhong(5)}斤`
    function tizhong(num) {
      return 188 + num
    }
    console.log(str4)
    //模板字符串alert的简写
    // alert("hello world");
    alert`Hello world`


    function fnc(stringArr, ...rest) {
      console.log(stringArr)//['你的名字是：','，你的年龄是','。']
      console.log(rest)//["张三",88]
    }
    var username = "张三"
    var myage = 88;
    fnc`你的名字是：${username}，你的年龄是${myage}。`
    // fnc("你的名字是：" + username + "，你的年龄是" + myage + "。")



  </script>
</body>

</html>